<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="流水单号">
              <el-input v-model="params.orderSn" placeholder="请输入流水单号" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="用户姓名">
              <el-input v-model="params.realname" placeholder="请输入姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="用户电话">
              <el-input v-model="params.username" placeholder="请输入用户电话" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-button style="margin-left:60px" type="primary" @click="searchfun">查询</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- table -->
    <div class="table">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="orderSn" align="center" label="流水单号" />
        <el-table-column prop="name" align="center" label="客户信息">
          <template slot-scope="scope">
            <div>姓名: {{ scope.row.realname }}</div>
            <div>电话： {{ scope.row.username | phonereg}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="name" align="center" label="服务商">
          <template slot-scope="scope">
            <div>姓名: {{ scope.row.serverRealname }}</div>
            <div>电话： {{ scope.row.serverUsername | phonereg}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="hospitalName" align="center" label="医院" />
        <el-table-column prop align="center" label="时间">
          <template slot-scope="scope">
            <div>创建： {{ scope.row.createdDate }}</div>
            <div>修改： {{ scope.row.orderDate }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="remark" align="center" label="备注" />
        <el-table-column prop="name" align="center" label="状态">
          <template slot-scope="scope">
            <div>{{ scope.row.status==0?'未处理':'已处理' }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="name" align="center" label="操作">
          <template slot-scope="scope">
            <div>
              <el-button v-if=" scope.row.status=='0' &&permissionJson.indexOf('AdminApplyErrorRecordProvider.getApplyErrorRecordDetail')" type="text" @click="deit(scope.row,1)">查看</el-button>
              <el-button v-if="scope.row.status=='0' && permissionJson.indexOf('AdminApplyErrorRecordProvider.dealStatus')" type="text" @click="deit(scope.row,0)">处理</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="block" style="margin: 40px 0;">
      <el-pagination
        :current-page="params.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
    <el-dialog v-if="dialogVisible" title="请填写异常处理备注：" :visible.sync="dialogVisible" width="20%">
      <el-input v-model="datas.remark" type="textarea" :rows="2" />
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="sure">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import abnormalTurnover from '@/api/abnormalTurnover/abnormalTurnover'
export default {
  data() {
    return {
      permissionJson: JSON.parse(localStorage.getItem('permissionJson')),
      params: {
        pageNum: 1,
        pageSize: 20,
        orderSn: '',
        realname: '',
        username: ''
      },
      tableData: [{ number: 100 }],
      total: 0,
      time: '',
      dialogVisible: false,
      datas: {
        id: '',
        status: '1',
        remark: ''
      }
    }
  },
  created() {
    this.list()
  },
  methods: {
    sure() {
      abnormalTurnover.dealStatus(this.datas).then(res => {
        console.log(res)
        this.$message.warning(res.data.msg)

        if (res.data.code == 0) {
          this.dialogVisible = false
          this.list()
        }
      })
    },
    searchfun() {
      this.params.pageNum = 1
      this.list()
    },
    list() {
      abnormalTurnover.list(this.params).then(res => {
        console.log(res)
        if (res.data.code == 0) {
          this.tableData = res.data.data.list
          this.total = res.data.data.count
        } else {
          this.$message.warning(res.data.msg)
        }
      })
    },
    handleSizeChange(val) {
      this.params.pageNum = 1
      this.params.pageSize = val
      this.list()
    },
    handleCurrentChange(val) {
      this.params.pageNum = val
      this.list()
    },
    deit(datas, type) {
      if (type == 0) {
        this.dialogVisible = true
        this.datas.id = datas.id
      } else {
        this.$router.push({
          name: 'abnormalTurnoverdetail',
          query: { id: datas.id }
        })
      }
    }
  }
}
</script>
